<?php
unset($params);
$params['sid'] = $sid;
$params['action'] = "order";
$orderurl = "$baseURL/$webDIR/?".encode_params($params);
//-----------------------------------------------------
$sql['type'] = "SELECT";
$sql['params'] = "to_char(s.date,'YYYY-MM-DD') as data,s.order_id,s.type,s.amount_total,s.amount_wholesale,c.client_id,c.username,(c.firstname||' '||c.lastname) as uname";
$sql['table'] = "sales AS s,clients AS c";
$sql['where'] = "s.reseller_id = '$id' AND s.client_id=c.client_id AND c.blocked=0";
$sql['options'] = "ORDER BY s.date DESC LIMIT 3";
$sql['return'] = "struct";
#$sql['return'] = "query";
//------------------------------------------------------
#exit($res = sql_exec($sql,$dbh81,'assoc'));
$res=sql_exec($sql,$dbh81,'assoc');
#print_r($res);
?>

<table class='bTable' cellspacing=0 cellpadding=0 width=100%>
  <tr>
	<th><?=translate('date');?></th>
	<th><?=translate('order_id');?></th>
	<th><?=translate('type');?></th>
	<th><?=translate('retail');?></th>
	<th><?=translate('wholesale');?></th>
	<th><?=translate('client');?></th>
	<th><?=translate('username');?></th>
  </tr>
  <?php
  if (empty($res)) {
  	?>
  	<tr>
		<td colspan="7" align="center"><?=translate('no_sales',array('url' => $orderurl));?></td>
	</tr>
	<?php } else {
		foreach ($res as $r) {
			unset($params);
			$params['sid'] = $sid;
			$params['action'] = "viewClients";
			$params['form_sent'] = "yes";
			$params['client_id'] = $r['client_id'];
			$clientUrl = "$baseURL/$webDIR/?".encode_params($params);
			echo "<tr>
				<td>".$r['data']."</td>
				<td>".$r['order_id']."</td>
				<td>".$r['type']."</td>
				<td align='right'>$".$r['amount_total']." USD</td>
				<td align='right'>$".$r['amount_wholesale']." USD</td>
				<td>".$r['uname']."</td>
				<td><a href='$clientUrl'>".$r['username']."</a></td>
			</tr>";
		}
	}
	?>
</table>
<br />
<img align="bottom" src="images/ico_fast_stats_home.gif" alt="Fast Stats">&nbsp;&nbsp;
	<?php
	$params[sid] = $sid;
	$params[action] = 'stats_general';
	$url = "$baseURL/$webDIR/?".encode_params($params);
	echo "<a href='$url' target='_blank'>".translate('general')."</a>  :  ";
	$params[sid] = $sid;
	$params[action] = 'stats_affiliates';
	$url = "$baseURL/$webDIR/?".encode_params($params);
	echo "<a href='$url' target='_blank'>".translate('affiliates')."</a>  :  ";
	$params[sid] = $sid;
	$params[action] = 'payments';
	$url = "$baseURL/$webDIR/?".encode_params($params);
	echo "<a href='$url'>".translate('p_history')."</a>";
	#echo "<a href='$url'>Payments History</a>  :  ";
	#echo "<a href=''>Accounting Manager</a>";
	?>
<br />